//
//  ZFMineViewController.swift
//  WeiBoAPP
//
//  Created by ios001 on 2021/8/27.
//  Copyright © 2021 zxf. All rights reserved.
//

import UIKit
import SnapKit

class ZFMineViewController: ZFBaseViewController {
    var headerView:ZYMineHeadView?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        createHeaderView()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.headerView?.refreshHeadView()
    }
    
    
    override func setupNavUI()  {
         super.setupNavUI()
        let setBtn = UIButton(type: UIButtonType.custom)
        setBtn.frame = CGRect(x: 0, y: 0, width: 40, height: 40)

        setBtn.setTitle("设置", for: .normal)
        setBtn.setTitleColor(UIColor.black, for: .normal)
        setBtn.addTarget(self, action: #selector(setBtnAction), for: .touchUpInside)
        navItem.rightBarButtonItems = [UIBarButtonItem.init(customView: setBtn)]
        
    }
    
    // 私有方法
    @objc private func setBtnAction() {
        self.navigationController?.pushViewController(ZYSetViewController.init(), animated: true)
    }
    
    func createHeaderView() {
        
        weak var weakSelf = self
        headerView = ZYMineHeadView(frame: CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: 150))
        headerView?.frofilePageActionBlock = {
            weakSelf?.jumpToFrofilePageAction()
        }
        headerView?.loginActionBlock = {
            weakSelf?.loginBtnAction()
        }
        
//        headerView.backgroundColor = UIColor.red
        self.tableView?.tableHeaderView = headerView
     
    }
    
    @objc private func jumpToFrofilePageAction () {
        
        let vc:ZFProfileViewController  = ZFProfileViewController.init()
        self.navigationController?.pushViewController(vc, animated: true)
        
    }
    
    @objc private func loginBtnAction () {
        // 登录跳转
        LoginTool.showLogin(vc: self) {[weak self] in
            self?.headerView?.refreshHeadView()
        }
        
    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
